package com.ssm.card.dao.mapper.equipment;

import com.github.pagehelper.PageInfo;
import com.ssm.card.dao.model.equipment.Equipment;
import com.ssm.upms.dao.mapper.ssm.LzDao;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* 设备管理 Dao
* @author GaoXiang
* @version 1.0
*/
@Repository
public class EquipmentDao extends LzDao<Equipment> {



    /**
    * 保存数据
    * @param equipment 实体对象
    * @return 实体id
    * @throws Exception 数据保存异常
    */
    public Integer insert(Equipment equipment) throws Exception {
        return insert("EquipmentMapper.insert",equipment);
    }

    /**
    * 根据 id 修改
    * @param equipment 带id的实体对象
    * @return 受影响的行数
    * @throws Exception 数据修改异常
    */
    public Integer updateById(Equipment equipment) throws Exception {
        return update("EquipmentMapper.updateById",equipment);
    }

    /**
    * 根据 id 删除
    * @param id 数据id
    * @return 受影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteById(String id) throws Exception {
        return delete("EquipmentMapper.deleteById",id);
    }

    /**
    * 根据 id 查找
    * @param id 实体id
    * @return 实体
    */
    public Equipment selectById(String id) {
        return selectOne("EquipmentMapper.selectById",id);
    }

    /**
    * 根据 id 批量删除
    * @param ids 要删除的id
    * @return 影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteByIds(List<String> ids) throws Exception {
        return delete("EquipmentMapper.deleteByIds",ids);
    }

    /**
    * 查询列表
    * @param map 参数
    * @return 列表
    */
    public PageInfo<Equipment> list(Map map) {
        return list("EquipmentMapper.list",map);
    }

    /**
    * 查询列表 带分页
    * @param map 参数
    * @param page 页码
    * @param size 每页大小
    * @return 列表
    */
    public PageInfo<Equipment> list(Map map, int page, int size) {
        return list("EquipmentMapper.list",map,new RowBounds(page,size));
    }
    /**
     * 某小区设备分布图
     * @param meter 参数
     * @return map 统计图
     */
    public List<Equipment> countName(Equipment meter) {
        return arrayList("EquipmentMapper.countName", meter);
    }
    /**
     * 某小区设备数量统计图
     * @param meter 参数
     * @return map 统计图
     */
    public Equipment countNumber(Equipment meter) {
        return selectOne("EquipmentMapper.countNumber", meter);
    }
    /**
     * 某小区设备类型分布图
     * @param map 参数
     * @return map 统计图
     */
    public List<Equipment> countName2(Map map) {
        return arrayList("EquipmentMapper.countName2", map);
    }
    /**
     * 某小区设备类型数量统计图
     * @param map 参数
     * @return map 统计图
     */
    public Equipment countNumber2(Map map) {
        return selectOne("EquipmentMapper.countNumber2", map);
    }


    public Long count(Map map){
        return  count("EquipmentMapper.count",map);
    }


    /**
     * 根据mac地址查询设备
     * @param mac 参数地址
     * @return map 统计图
     */
    public Equipment findByMac(String mac){
        return selectOne("EquipmentMapper.findByMac",mac);
    }


    /**
     * 根据单元的id绑定设备
     * @param unitId 单元的id
     * @return 实体
     */
    public  Equipment  chooseEquipment(String unitId){ return selectOne("EquipmentMapper.chooseEquipment",unitId);}

    /**
     * 根据房屋id查询设备id
     * @param roomId
     * @return
     */
    public Equipment selectByRoomId(String roomId){
        return selectOne("EquipmentMapper.selectByRoomId",roomId);
    }

    public Equipment findById(String id) {
        return selectOne("EquipmentMapper.findById", id);
    }

    public Integer deleteByResidenceId(String id) throws Exception{
        return delete("EquipmentMapper.deleteByResidenceId",id);
    }
    /**
     * 查询小区下的所有设备
     * @param id
     * @return
     */
    public List<Equipment> selectByResidenceId(String id) {
        return arrayList("EquipmentMapper.selectByResidenceId",id);
    }
    /**
     * 查询楼栋下的所有设备
     * @param id
     * @return
     */
    public List<Equipment> selectByBuildingId(String id) {
        return arrayList("EquipmentMapper.selectByBuildingId",id);
    }
    /**
     * 查询单元下的所有设备
     * @param id
     * @return
     */
    public List<Equipment> selectByUnitId(String id) {
        return arrayList("EquipmentMapper.selectByUnitId",id);
    }
}
